{extend name="base" /}
{block name="content"}
<script src="__STATIC__/public/My97DatePicker/WdatePicker.js"></script>
<div class="g-main">
    <div class="m-main-title">
        <div class="m-container-fluid">
            <a href="{:url('index/welcome')}"><i class="icon icon-home"></i>首页</a>
            <span class="icon-angle-right"></span>
            <span>商城</span>
            <span class="icon-angle-right"></span>
            <span>活动管理</span>
            <span class="icon-angle-right"></span>
            <span>{$info ? '编辑' : '添加'}活动商品</span>
            <a class="u-flush"><i class="icon-repeat"></i></a>
        </div>
    </div>
    <div class="m-main-content">
        <div class="m-container">
            <div class="m-form">
                <form class="layui-form" id="j_form">
                    <table class="m-table">
                        <thead>
                        <tr>
                            <th colspan="2">{$info ? '编辑' : '添加'}活动商品</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>

                            <td><label for="">活动名称<em>*</em></label></td>

                            <td>

                                <div class="lay-select">

                                    <select name="activity_id">

                                        <option value="0">请选择活动</option>

                                        {foreach name="activity" item="activity"}

                                        <option value="{$activity.id}"{if condition="$info['activity_id'] eq $activity['id']"} selected{/if}>{$activity.title}</option>

                                        {/foreach}

                                    </select>

                                </div>

                            </td>

                        </tr>
                        <tr id="j_member_points">
                            <td width="15%"><label for="goods_id">选择商品<em>*</em></label></td>
                            <td>

                                <input type="text" class="u-ipt u-ipt-longer" id="goods_id1" placeholder="请输入商品名称" readonly                                         {foreach name='good' item='goods'}
                                       {if condition="$info.goods_id eq $goods.id"}value="{$goods.goods_name}" {/if}
                                {/foreach} />
                                <input type="hidden" class="u-ipt u-ipt-longer" name="goods_id" id="goods_id" placeholder="请输入商品名称" readonly value="{$info.goods_id}" /><span><a class="u-edit" data-id="{$info.goods_id}" data-key="goods_id">修改</a></span></td>
                        </tr>
                        <tr>
                            <td width="15%"><label for="goods_name">团购商品标题<em>*</em></label></td>
                            <td><input type="text" class="u-ipt u-ipt-longer" name="goods_name" id="goods_name" placeholder="请输入团购商品标题" value="{$info.goods_name}" /></td>
                        </tr>
                        <tr>
                            <td width="15%"><label for="describe">团购商品描述<em>*</em></label></td>
                            <td><input type="text" class="u-ipt u-ipt-longer" name="describe" id="describe" placeholder="请输入团购商品描述" value="{$info.describe}" /></td>
                        </tr>
                        <tr>
                            <td width="15%"><label for="promotion_price">团购价格<em>*</em></label></td>
                            <td><input type="text" class="u-ipt u-ipt-longer" name="promotion_price" id="promotion_price" placeholder="请输入团购价格" value="{$info.promotion_price}" /></td>
                        </tr>
                        <tr>
                            <td width="15%"><label for="num">团购数量<em>*</em></label></td>
                            <td><input type="text" class="u-ipt u-ipt-longer" name="num" id="num" placeholder="请输入团购数量" value="{$info.num}" /></td>
                        </tr>
                        <tr>
                            <td width="15%"><label for="list_order">排序<em>*</em></label></td>
                            <td><input type="text" class="u-ipt u-ipt-longer" name="list_order" id="list_order" placeholder="请输入活动排序" value="{$info.list_order}" /></td>
                        </tr>
                        <!-- <tr>
                            <td width="15%"><label for="pbegin">开始时间</label></td>
                            <td><input type="text" name="pbegin" class="u-ipt u-ipt-long" id="pbegin" placeholder="开始时间" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" value="{$info.pbegin ? date('Y-m-d',$info.pbegin) : date('Y-m-d', time())}" readonly=""></td>
                        </tr>
                        <tr>
                            <td width="15%"><label for="pend">结束时间</label></td>
                            <td><input type="text" name="pend" class="u-ipt u-ipt-long" id="pend" placeholder="结束时间" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" value="{$info.pend ? date('Y-m-d',$info.pend) : date('Y-m-d', time())}" readonly=""><span>默认到所选日期的23:59:59</span></td>
                        </tr> -->
                        <input type="hidden" value="{$info.register_time ? $info.register_time : time()}" name="register_time" id="register_time"/>
                    </table>
                    <div class="m-form-btn"><input type="hidden" name="id" value="{$info.id}"><button id="j_btn" class="u-btn">确定提交</button></div>
                </form>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="extrajs"}
<script>
    layui.use(['layer', 'form', 'upload'], function() {
        $('.u-edit').on('click', function () {
            var $input = $(this).parent().prev();
            var $that = $(this);
            var key = $that.attr('data-key');
            var id = $that.attr('data-id');
            var title = key == 'points' ? '搜索商品名' : '搜索商品名';

            layer.open({
                type: 1,
                title: title,
                skin: 'layui-layer-rim', //加上边框
                area: ['420px', '400px'], //宽高
                content: '<div class="m-edit-form"><input type="text" id="name" class="u-ipt name"><p>直接输入要搜索的商品名</p><input type="button" class="u-btn" id="sousuo"  value="搜索" /></div>'
            });
        });
        /*点击搜索  搜索商品名*/
        $('body').on('click', '#sousuo', function () {
            var html = '';
            $('.m-edit-form p:nth-of-type(2)').remove();
            $('.m-edit-form input:nth-of-type(3)').remove();
            var name = $(this).parent('.m-edit-form').find('.name').val();
            $.post('{:url("goods")}', {name:name}, function (ret) {
                if (ret) {
                    var obj = eval(ret);
                    html += "<p>";
                    for(var i=0; i<obj.length; i++)
                    {
                        var id = obj[i].id;
                        var goodsname = obj[i].goods_name;
                        html += '<input type="radio" name="a" value="' + goodsname + '" data="' + id + '"/>' + goodsname     ;
                    }
                    html += "</p><input type=\"button\" class=\"u-btn\" id=\"tijiao\"  value=\"提交\" />";
                    $('.m-edit-form').append(html);
                }
            }, 'json');
        });
        /*点击弹框的提交*/
        $('body').on('click', '#tijiao', function () {
            $("input[name='a']:checked").each(function(){
                $('#goods_id1').val($(this).val());
                $('#goods_id').val($(this).attr('data'));
            })
            layer.closeAll();
        });
    })
</script>
{/block}